let History = require('../Model/History').HistoryModel

/*
function HistoryRecode(req, res, next) {
  if (req.path === '/login' || req.path === '/login_out') {
    let history = {
      username: req.body.username || '未知登录者',
      uid: '-----',
      oper: '登录/登出',
      ipaddr: req.id,
    }
    new History(history).save(function (err, doc) {
    })
    console.log(history)
    next()
  } else {
    // isLogin
    let token = req.get("Authorization") || ''
    let user = token ? {username: JSON.parse(token).username, uid: JSON.parse(token).uid}
      : {username: '未知访客', uid: '------'}
    let history = {
      username: user.username,
      uid: user.uid,
    }
    // path
    history.path = req.method
    // method
    switch (req.method) {
      case 'GET' :
        history.oper = '查看'
        break
      case 'POST' :
        history.oper = '创建'
        break
      case 'PUT' :
        history.oper = '更新'
        break
      case 'DELETE' :
        history.oper = '删除'
        break
      default :
        history.oper = '未知'
    }
    // ip_address
    history.ipaddr = req.ip
    // state
    history.state = Boolean(token)

    new History(history).save(function (err, doc) {
    })
    console.log(history)
    next()
  }
}
*/
module.exports = HistoryRecode